<?php

class Bill_Finder_Simple extends Bill_Finder_Abstract {

	private function _getLastDate() {
		//return Util::date("Ym01");
		$tmp = $this->select()->getAdapter()->query("select max(idate) as last_date from bill_hdr")->fetchAll();
		
		if (isset($tmp[0]['last_date'])) 
			return $tmp[0]['last_date'];
		else 
			throw new Exception("Can't determine last date");
		
	}
	
	protected function prepend($request) {
		$this->_select->from('account',array("bill"=>"acc_key"));

		$this->_select->join(array('bh' => 'bill_hdr'),"bh.acc_n = account.acc_n",
			array("pid"=>"person_id", "id"=>"acc_n","sum"=>"amm_end","term"=>"time_dolg"));
		
		$this->_select->where('bh.idate = ?', (int)$this->_getLastDate());
		
		return $this;
	}
	
	

	

	
	
}